package co.com.smart.eagle.client.activity;

import java.util.List;

import co.com.smart.eagle.client.EagleCallBack;
import co.com.smart.eagle.client.factory.EagleFactory;
import co.com.smart.eagle.client.rpcservices.login.LoginService;
import co.com.smart.eagle.client.rpcservices.login.LoginServiceAsync;
import co.com.smart.eagle.client.rpcservices.resources.ResourcesService;
import co.com.smart.eagle.client.rpcservices.resources.ResourcesServiceAsync;
import co.com.smart.eagle.client.view.CrearRecursosView;
import co.com.smart.eagle.client.view.CrearRecursosView.Presenter;
import co.com.smart.eagle.client.view.util.SmartLoading;
import co.com.smart.eagle.infrastructure.dto.AplicacionesDTO;
import co.com.smart.eagle.infrastructure.dto.RecursosDTO;
import co.com.smart.eagle.infrastructure.dto.RolesDTO;

import com.google.gwt.activity.shared.AbstractActivity;
import com.google.gwt.core.shared.GWT;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.user.client.ui.AcceptsOneWidget;

public class CrearRecursosActivity extends AbstractActivity implements Presenter {

	private CrearRecursosView view;
	private ResourcesServiceAsync servicesResource = GWT.create(ResourcesService.class);
	private LoginServiceAsync servicesLogin = GWT.create(LoginService.class);
	
	public CrearRecursosActivity(EagleFactory eagleFactory) {
		view = eagleFactory.getCrearRecursosView();
		view.setPresenter(this);
		view.cleanForm();
		cargarRecursos();
	}
	
	@Override
	public void start(AcceptsOneWidget panel, EventBus eventBus) {
		panel.setWidget(view);
	}
	
	@Override
	public void crearRecurso() {
		

	}

	@Override
	public void cargarRecursos() {
		EagleCallBack<List<RecursosDTO>> callBack = new EagleCallBack<List<RecursosDTO>>(true) {
			@Override
			public void success(List<RecursosDTO> result) {
				view.setRecursos(result);
				cargarApps();
			}
		};
		SmartLoading.getInstance().show();
		servicesResource.getResources(callBack);

	}

	@Override
	public boolean validateCreateRecurso() {
		
		return false;
	}

	@Override
	public void editRecurso(RecursosDTO Recurso) {
		

	}

	@Override
	public void deleteRecurso(RecursosDTO Recurso) {
		

	}

	@Override
	public void cargarApps() {
		EagleCallBack<List<AplicacionesDTO>> callBack = new EagleCallBack<List<AplicacionesDTO>>(true) {
			@Override
			public void success(List<AplicacionesDTO> result) {
				// combobox app
				cargarRoles();
			}
		};
		
		servicesLogin.getApplications(callBack);
		
	}

	@Override
	public void cargarRoles() {
		EagleCallBack<List<RolesDTO>> callBack = new EagleCallBack<List<RolesDTO>>(true) {
			@Override
			public void success(List<RolesDTO> result) {
				//combox roles
			}
		};
		
		servicesLogin.getRoles(callBack);
	}


}
